package com.example.xgakj.newterminal.ui.framents;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.xgakj.newterminal.R;
import com.example.xgakj.newterminal.base.BaseFragment;
import com.example.xgakj.newterminal.models.LoginModel;
import com.example.xgakj.newterminal.ui.activities.LoginActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @author Administrator
 * @date 2017-10-18
 */

public class SettingsFragment extends BaseFragment {


    @BindView(R.id.tv_userInfo)
    TextView tvUserInfo;
    @BindView(R.id.tv_alarm_setting)
    TextView tvAlarmSetting;
    @BindView(R.id.tv_device)
    TextView tvDevice;
    @BindView(R.id.tv_loginOut)
    TextView tvLoginOut;
    @BindView(R.id.tv_exit)
    TextView tvExit;
    Unbinder unbinder;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = inflater.inflate(R.layout.fragment_settings, container, false);

        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.tv_userInfo, R.id.tv_alarm_setting, R.id.tv_device, R.id.tv_loginOut, R.id.tv_exit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_userInfo:
                break;
            case R.id.tv_alarm_setting:
                break;
            case R.id.tv_device:
                break;
            case R.id.tv_loginOut:
                logOut(getActivity());
                break;
            case R.id.tv_exit:
                getActivity().finish();
                break;
            default:
        }
    }

    /**
     * 注销登录，返回登录界面
     * @param activity
     */
    private void logOut(Activity activity) {
        LoginModel loginModel=new LoginModel();
        loginModel.loginOut(activity);
        Intent intent=new Intent(activity, LoginActivity.class);
        startActivity(intent);
        activity.finish();
    }
}
